package com.paperyy.module.controller;

import com.paperyy.module.bean.User;
import com.paperyy.module.dao.UserDao;
import com.paperyy.module.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserServiceImpl userService;
    @Autowired
    private UserDao userDao;

    @GetMapping("/findUser")
    public String findUser(Model model,Integer uid) {
        //获取当前时间
        Date day=new Date();
        //根据uid获取用户
        User user = userService.findUser(uid);
        //判断时间
        //相等，结果为0
        //day时间在用户时间之前，结果为-1
        //day时间在用户时间之后，结果为1
        Integer res = day.compareTo(user.getTime());
        //会员到期判断
            if (res < 0) {
                //1表示是会员
                user.setV(1);
                userDao.updateById(user);
            }
            model.addAttribute("msg",user);

        return "user";
    }





}
